package FWK.components;

import java.awt.Cursor;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;

public class FwkButton extends JButton implements FwkComponent {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private MouseListener listener;

	public FwkButton(String content) {
		this();
		this.setText(content);
	}

	public FwkButton() {

		this.setFocusable(false);
		this.setSelected(false);
		setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		setMargin(new Insets(0, 0, 0, 0));
		this.setContentAreaFilled(false);
		listener = new RollOverListener();
		this.addMouseListener(listener);
	}

	public void activate() {
		this.setEnabled(true);
		this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
	}

	public void standBy() {
		this.setEnabled(false);
		this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
	}

	public void setEnabled(boolean eneable) {
		super.setEnabled(eneable);
		if (eneable)
			this.addMouseListener(listener);
		else
			this.removeMouseListener(listener);

	}

	private class RollOverListener extends MouseAdapter {

		public void mouseEntered(MouseEvent e) {
			FwkButton b = FwkButton.this;
			b.setContentAreaFilled(true);
		}

		public void mouseExited(MouseEvent e) {
			FwkButton b = FwkButton.this;
			b.setContentAreaFilled(false);
		}
	}
}